import type { Profile } from '@/types/user'
import { setLocalToken ,removeLocalToken, getLocalToken } from '@/utils/auth'
import Cookies from 'js-cookie'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user', () => {
  const token = ref(getLocalToken() || '')
  const data=ref(Cookies.get('form')||'')
  const setToken=(val:string)=>{
    token.value=val
    setLocalToken(token.value)
  }
  const profile=ref<Profile>({} as Profile)
  const setProfile=(val:Profile)=>{
    profile.value=val
  }
  const ClearProfile=()=>{
    profile.value={} as Profile
  }
  const ClearToken=()=>{
    token.value=''
    removeLocalToken()
  }
  return {
    data,
    token,
    setToken,
    ClearToken,
    profile,
    setProfile,
    ClearProfile
  }
})
